package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type Web2Handler struct {
}

func (*Web2Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("web2"))
}
func main() {
	router := gin.Default()
	// 如果文件很大，可以设置最大内存存储量
	router.MaxMultipartMemory = 100 << 20 // 8 MiB
	router.GET("/", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"message": "web2"})
	})
	router.POST("/upload", func(c *gin.Context) {
		// 单文件上传
		file, err := c.FormFile("file")
		if err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}

		// 保存文件到服务器
		if err := c.SaveUploadedFile(file, "./uploads/"+file.Filename); err != nil {
			c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}

		c.JSON(http.StatusOK, gin.H{"message": "web2 文件上传成功", "filename": file.Filename})
	})
	router.Run(":9091")
	//err := http.ListenAndServe(":9091", &Web2Handler{})
	//if err !=nil {
	//	fmt.Println("start server error,info:",err)
	//}

}
